<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            物流中转
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">车牌号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择车牌号" id="carCode" value=""/>
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectCarNum()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">目标位置</div>
                    <select id="position">
                    </select>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">备注</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入备注" id="remark" value="">
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()" id="submitButton">保存</div>
        <div style="width:100%;margin-top:4%;"></div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var code = "CAR_NUM";
    var codeC = "" //选中返回车牌号 编码
    var nameC = "" //选中返回车牌号 号码

    //初始化查询明细数据和下拉框下拉框
    apiready = function () {

     //查询目标位置
     selectPosition();
    }

    function selectPosition(){
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUdiList";
        var data = {
            values: {
                code: "TARGET_LOC",
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("position"), html);
            }
        });
    }

    //选择车牌号
    function goSelectCarNum() {
        api.openWin({
            name: 'uwmSelectCarCode',
            url: 'uwmSelectCarCode.html',
            pageParam: {
                name: "logisticsTransfer",
                code:code,
            }
        });
    }

    //车牌选择后回调函数
    function setCarCode(code, name) {
        nameC = name
        $("#carCode").val(name)
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }

    //保存按钮
    function save() {
        if (!clickThrottle()) {
            return;
        }
        var carCode = $("#carCode").val();
        var position = $("#position").val();
        var remark = $("#remark").val();
        const submitButton = document.getElementById('submitButton');
        submitButton.style.pointerEvents = "none"
        //车牌号非空校验
        if (carCode == "" || carCode == null || carCode == undefined) {
            api.toast({
                msg: '请选择车牌号',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }
        //目标位置非空校验
        if (position == "" || position == null || position == undefined) {
            api.toast({
                msg: '请选择目标位置',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveLogistics";
        var data = {
            values: { 
                un: un,
                remark: remark,
                carCode: carCode,
                position: position,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                } else if (myobj.code == 'E') {
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                submitButton.style.pointerEvents = "auto"
            }
        });
    }
</script>

</html>